package com.itheima.steawmdemo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.stream.Stream;

public class StreamDemo2 {
    public static void main(String[] args) {
        //单例集合
//        method1();
        // 双列集合
//        method2();
        // 数组
//        method3();
        // 同种数据类型的多个数据
        method4();
    }

    private static void method4() {
        Stream.of(1,2,3,4,5,6,7,8).forEach(i -> System.out.println(i));
    }

    private static void method3() {
        int[] arr = {1, 2, 3, 4, 5};
        Arrays.stream(arr).forEach(s -> System.out.println(s));
    }

    private static void method2() {
        HashMap<String, Integer> hm = new HashMap<>();
        hm.put("zhangsan", 23);
        hm.put("lisi", 24);
        hm.put("wangwu", 25);
        hm.put("zhaoliu", 26);
        hm.put("qianqi", 27);

        // 双列集合不能直接获取Stream流
        // keySet
        hm.keySet().stream().forEach(s -> System.out.println(s));
        // entrySet
        hm.entrySet().stream().forEach(e -> System.out.println(e));

    }

    private static void method1() {
        ArrayList<String> list = new ArrayList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");

//        Stream<String> stream = list.stream();
//        stream.forEach(s -> System.out.println(s));
        list.stream().forEach(s -> System.out.println(s));
    }
}
